<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 17:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Airline" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%
    // 获取要编辑的航空公司ID
    String aid = request.getParameter("aid");

    // 创建DB_Airline实例
    DB_Airline dbAirline = new DB_Airline();
    // 构建查询输入列表
    List<String> findInput = new ArrayList<>();
    findInput.add(aid);
    // 用于存储查询结果
    List<String> returnList = new ArrayList<>();
    // 执行查询操作，获取要编辑的航空公司信息
    dbAirline.find("aid", aid, returnList);

    if (!returnList.isEmpty()) {
        // 获取航空公司的各项信息
        String fid = returnList.get(1);
        String[] dateParts = returnList.get(2).split("-");
        String position = returnList.get(3);
        String remain = returnList.get(4);
%>
<!DOCTYPE html>
<html>
<head>
    <title>编辑航空公司</title>
</head>
<body>
<h2>编辑航空公司</h2>
<form action="updateAirline.jsp" method="post">
    <input type="hidden" name="aid" value="<%= aid %>">
    <label for="fid">航班ID:</label>
    <input type="text" id="fid" name="fid" value="<%= fid %>" required><br>
    <label for="dateYear">日期 - 年:</label>
    <select id="dateYear" name="dateYear">
        <% for (int year = 2024; year <= 2030; year++) { %>
        <option value="<%= year %>" <%= year == Integer.parseInt(dateParts[0])? "selected" : "" %>><%= year %></option>
        <% } %>
    </select>
    <label for="dateMonth">月:</label>
    <select id="dateMonth" name="dateMonth">
        <% for (int month = 1; month <= 12; month++) { %>
        <option value="<%= String.format("%02d", month) %>" <%= month == Integer.parseInt(dateParts[1])? "selected" : "" %>><%= String.format("%02d", month) %></option>
        <% } %>
    </select>
    <label for="dateDay">日:</label>
    <select id="dateDay" name="dateDay">
        <% for (int day = 1; day <= 31; day++) { %>
        <option value="<%= String.format("%02d", day) %>" <%= day == Integer.parseInt(dateParts[2])? "selected" : "" %>><%= String.format("%02d", day) %></option>
        <% } %>
    </select><br>
    <label for="position">位置:</label>
    <input type="text" id="position" name="position" value="<%= position %>" required><br>
    <label for="remain">剩余票数:</label>
    <input type="number" id="remain" name="remain" value="<%= remain %>" required><br>
    <input type="submit" value="更新航空公司">
</form>
</body>
</html>
<% } else {
    out.println("未找到要编辑的航空公司");
} %>